package com.ruoyi.web.controller.monitor;

import com.ruoyi.base.domain.BusWaterSegment;
import com.ruoyi.base.service.IBusWaterSegmentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.monitor.domain.BusWaterAutomonitorevaluateHourdata;
import com.ruoyi.monitor.service.IBusWaterAutomonitorevaluateHourdataService;
import com.ruoyi.monitor.service.IBusWaterIntegrationevaluatedataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 自动站断面小时评价数据Controller
 * 
 * @author maliang
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/monitor/autovaluatehourdata")
public class BusWaterAutomonitorevaluateHourdataController extends BaseController
{
    @Autowired
    private IBusWaterAutomonitorevaluateHourdataService busWaterAutomonitorevaluateHourdataService;
    @Autowired
    private IBusWaterIntegrationevaluatedataService busWaterIntegrationevaluatedataService;
    @Autowired
    private IBusWaterSegmentService busWaterSegmentService;

    /**
     * 查询自动站断面小时评价数据列表
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autovaluatehourdata:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusWaterAutomonitorevaluateHourdata busWaterAutomonitorevaluateHourdata)
    {
        startPage("sampletime desc");
        List<Map> list = busWaterAutomonitorevaluateHourdataService.selectBusWaterAutomonitorevaluateHourdataAndItemList(busWaterAutomonitorevaluateHourdata);
        return getDataTable(list);
    }

    @GetMapping("/getLastData")
    public AjaxResult getLastData(String segmentId){
        return AjaxResult.success(busWaterAutomonitorevaluateHourdataService.getLastData(segmentId));
    }
    /**
     * 导出自动站断面小时评价数据列表
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autovaluatehourdata:export')")
    @Log(title = "自动站断面小时评价数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWaterAutomonitorevaluateHourdata busWaterAutomonitorevaluateHourdata)
    {
        List<BusWaterAutomonitorevaluateHourdata> list = busWaterAutomonitorevaluateHourdataService.selectBusWaterAutomonitorevaluateHourdataList(busWaterAutomonitorevaluateHourdata);
        ExcelUtil<BusWaterAutomonitorevaluateHourdata> util = new ExcelUtil<BusWaterAutomonitorevaluateHourdata>(BusWaterAutomonitorevaluateHourdata.class);
        util.exportExcel(response, list, "自动站断面小时评价数据数据");
    }

    /**
     * 获取自动站断面小时评价数据详细信息
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autovaluatehourdata:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(busWaterAutomonitorevaluateHourdataService.selectBusWaterAutomonitorevaluateHourdataById(id));
    }

    /**
     * 新增自动站断面小时评价数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autovaluatehourdata:add')")
    @Log(title = "自动站断面小时评价数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWaterAutomonitorevaluateHourdata busWaterAutomonitorevaluateHourdata)
    {
        return toAjax(busWaterAutomonitorevaluateHourdataService.insertBusWaterAutomonitorevaluateHourdata(busWaterAutomonitorevaluateHourdata));
    }

    /**
     * 修改自动站断面小时评价数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autovaluatehourdata:edit')")
    @Log(title = "自动站断面小时评价数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusWaterAutomonitorevaluateHourdata busWaterAutomonitorevaluateHourdata)
    {
        return toAjax(busWaterAutomonitorevaluateHourdataService.updateBusWaterAutomonitorevaluateHourdata(busWaterAutomonitorevaluateHourdata));
    }

    /**
     * 删除自动站断面小时评价数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autovaluatehourdata:remove')")
    @Log(title = "自动站断面小时评价数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busWaterAutomonitorevaluateHourdataService.deleteBusWaterAutomonitorevaluateHourdataByIds(ids));
    }

    @GetMapping("/overview/{id}")
    public AjaxResult overview(@PathVariable("id") String id){
        BusWaterSegment busWaterSegment = busWaterSegmentService.selectBusWaterSegmentByID(id);
        if("1".equals(busWaterSegment.getIsmanual())){
            Map map = busWaterIntegrationevaluatedataService.overview(id);
            return AjaxResult.success(map);
        }else{
            Map map = busWaterAutomonitorevaluateHourdataService.overview(id);
            return AjaxResult.success(map);
        }
    }

    @GetMapping("/statisItemCount")
    public AjaxResult statisItemCount(String id,String startTime,String endTime){
        return AjaxResult.success(busWaterAutomonitorevaluateHourdataService.statisItemCount(id,startTime,endTime));
    }

    @GetMapping("/trendStatis")
    public AjaxResult trendStatis(String id,String startTime,String endTime,String items){
        return AjaxResult.success(busWaterAutomonitorevaluateHourdataService.trendStatis(id,startTime,endTime,items));
    }

    @GetMapping("/newlist")
    public TableDataInfo newlist(BusWaterAutomonitorevaluateHourdata busWaterAutomonitorevaluateHourdata)
    {
        startPage();
        busWaterAutomonitorevaluateHourdata.setIsAuto("1");
        busWaterAutomonitorevaluateHourdata.setIsDrink("0");
        List<Map> list = busWaterAutomonitorevaluateHourdataService.selectBusWaterAutomonitorevaluateNewHourAndItemdataList(busWaterAutomonitorevaluateHourdata,"Auto");
        return getDataTable(list);
    }

    /**
     * 水质级别趋势
     * @param id
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/trendQuality")
    public AjaxResult trendQuality(String id,String startTime,String endTime){
        return AjaxResult.success(busWaterAutomonitorevaluateHourdataService.trendQuality(id,startTime,endTime));
    }
}
